package com.dream.springmvc.filter;

import com.dream.springmvc.filter.operators.StringOperator;
import com.dream.springmvc.value.TextValue;
import com.dream.springmvc.value.Value;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

/**
 * @author zhaoshichang
 */
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
@NoArgsConstructor
@Data
public abstract class AbstractTextFilter<T extends TextValue> extends FilterBase<T> {
    private StringOperator op;

    @Override
    protected boolean supports(Value<?> value) {
        return value instanceof TextValue;
    }

    @Override
    protected boolean doMeet(T other) {
        return op.getOpf().eval(getVal().getValue(), other.getValue());
    }
}
